From 265151e1b8667ea383d47640f657d1eb598b5688 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 11 Nov 2007 14:12:24 +0000 Subject: [PATCH] Keep a cache of the linear version of BablImage's needed for BablFormats around. This reduces the constant overhead for conversions. * babl/babl-classes.h: added .image_template field to BablFormat. * babl/babl-format.c: (format_new): make .image_template NULL by defualt. * babl/babl-image.c: (babl_image_from_linear): use .image_template if available instead of creating our own BablImage from scratch. * babl/babl-memory.c: (babl_free): special case freeing of BablImage and BablFormat to do the extra juggling needed for the image_template cache. svn path=/trunk/; revision=248 --- ChangeLog | 15 +++++++++++++++ babl/babl-classes.h | 5 ++++- babl/babl-format.c | 1 + babl/babl-image.c | 18 ++++++++++++++++-- babl/babl-memory.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c92fa56..ea0e623 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-11-11 Øyvind Kolås + + Keep a cache of the linear version of BablImage's needed for + BablFormats around. This reduces the constant overhead for + conversions. + + * babl/babl-classes.h: added .image_template field to BablFormat. + * babl/babl-format.c: (format_new): make .image_template NULL by + defualt. + * babl/babl-image.c: (babl_image_from_linear): use .image_template if + available instead of creating our own BablImage from scratch. + * babl/babl-memory.c: (babl_free): special case freeing of BablImage + and BablFormat to do the extra juggling needed for the image_template + cache. + 2007-11-10 Øyvind Kolås * babl/babl-fish-stats.c: (table_destination_each): improve diff --git a/babl/babl-classes.h b/babl/babl-classes.h index 7471b8b..dba18e0 100644 --- a/babl/babl-classes.h +++ b/babl/babl-classes.h @@ -168,6 +168,9 @@ typedef struct int components; BablComponent **component; BablType **type; + void *image_template; /* image template for use with + linear (non-planer) images */ + BablSampling **sampling; BablModel *model; int bytes_per_pixel; @@ -183,8 +186,8 @@ typedef struct BablModel *model; /*< (always known) */ int components; BablComponent **component; - BablSampling **sampling; BablType **type; + BablSampling **sampling; char **data; int *pitch; int *stride; diff --git a/babl/babl-format.c b/babl/babl-format.c index 702752c..1fa6923 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -102,6 +102,7 @@ component_found: } babl->format.loss = -1.0; + babl->format.image_template = NULL; return babl; } diff --git a/babl/babl-image.c b/babl/babl-image.c index ad052a3..bf9c07c 100644 --- a/babl/babl-image.c +++ b/babl/babl-image.c @@ -91,8 +91,22 @@ babl_image_from_linear (char *buffer, switch (format->class_type) { case BABL_FORMAT: - model = (BablModel *) format->format.model; components = format->format.components; + if (format->format.image_template != NULL) /* single item cache for speeding + up subsequent use of linear buffers + for subsequent accesses + */ + { + babl = format->format.image_template; + format->format.image_template = NULL; + for (i = 0; i < components; i++) + { + babl->image.data[i] = buffer + offset; + offset += (format->format.type[i]->bits / 8); + } + return babl; + } + model = (BablModel *) format->format.model; memcpy (component, format->format.component, sizeof (Babl *) * components); memcpy (sampling, format->format.sampling, sizeof (Babl *) * components); @@ -136,7 +150,7 @@ babl_image_from_linear (char *buffer, } babl = image_new ( - (BablFormat *) format, + (BablFormat *) format!=model?format:NULL, model, components, component, sampling, type, data, pitch, stride); return babl; diff --git a/babl/babl-memory.c b/babl/babl-memory.c index d82953e..3dd2f10 100644 --- a/babl/babl-memory.c +++ b/babl/babl-memory.c @@ -140,6 +140,49 @@ void babl_free (void *ptr, ...) { + /* XXX: + * Extra logic to make the bookeeping of BablImage cached + * templates work out correctly, by using a babl_image_destroy + * and custom destroy functions for babl_format this would be + * avoided and the extra overhead not needed for non image/format + * typed allocations. + */ + if (BABL_IS_BABL (ptr)) + { + switch (BABL (ptr)->instance.class_type) + { + case BABL_IMAGE: + { + BablFormat *format = BABL(ptr)->image.format; + if (format) + { + if (format->image_template == NULL) + { + format->image_template = ptr; + return; + } + else + { + } + } + } + break; + case BABL_FORMAT: + { + BablFormat *format = ptr; + if (format->image_template != NULL) + { + BAI (format->image_template)->signature = NULL; + free_f (BAI (format->image_template)); + frees++; + } + format->image_template = NULL; + } + break; + default: + break; + } + } if (!ptr) return; if (!IS_BAI (ptr)) -- 2.30.2